﻿@model BBICMS.Application.InputModels.Products.ProductIM
@{
    ViewBag.Title = "编辑" + EntityNames.Product;
    ViewBag.PageTitle = ViewBag.Title + "_内容";
}

@section Header{
    <link href="~/plugins/SigFinder/SigFinder.min.css" rel="stylesheet" />
    <link href="~/plugins/webuploader/webuploader.css" rel="stylesheet" />

}

<div class="panel panel-default">
    <header class="panel-heading">
        <span class="glyphicon glyphicon-edit"></span> @ViewBag.Title
    </header>

    <section class="panel-body">

        @using (Ajax.BeginForm("Edit", null, new AjaxOptions
    {

        HttpMethod = "POST",
        OnBegin = "onBeginSave",
        OnComplete = "onCompleteSave",
        OnSuccess = "updateSuccess"

    }, new { @class = "form-horizontal", role = "form" }))
    {

        @Html.AntiForgeryToken()
        @Html.ValidationSummary(true)

        @Html.HiddenFor(model => model.Id)


        <div class="form-group">
            @Html.LabelFor(model => model.ProductNo, new { @class = "col-md-2 control-label" })
            <div class="col-md-10">
                @Html.TextBoxFor(model => model.ProductNo, new { @class = "form-control", placeholder = Labels.ProductNo })

                @Html.ValidationMessageFor(model => model.ProductNo)
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.Title, new { @class = "col-md-2 control-label" })
            <div class="col-md-10">
                @Html.TextBoxFor(model => model.Title, new { @class = "form-control", placeholder = Labels.Title })

                @Html.ValidationMessageFor(model => model.Title)
            </div>
        </div>


        <div class="form-group">
            @Html.LabelFor(model => model.Lang, new { @class = "col-md-2 control-label" })
            <div class="col-md-5">
                @Html.DropDownListFor(model => model.Lang, (SelectList)ViewBag.Langs, new { @class = "form-control", placeholder = Labels.Lang })
                @Html.ValidationMessageFor(model => model.Lang)
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.CategoryId, new { @class = "col-md-2 control-label" })
            <div class="col-md-5">
                @Html.DropDownListFor(model => model.CategoryId, (SelectList)ViewBag.Categories, "--" + EntityNames.Category + "--", new { @class = "form-control", placeholder = ModelMetadata.FromLambdaExpression(x => x.CategoryId, ViewData).Watermark })
                @Html.ValidationMessageFor(model => model.CategoryId)
            </div>
        </div>



        <div class="form-group">
            @Html.LabelFor(model => model.Thumbnail, new { @class = "col-md-2 control-label" })
            <div class="col-md-5">
                <div class="input-group">
                    @Html.TextBoxFor(model => model.Thumbnail, new { @class = "form-control", placeholder = Labels.Thumbnail })
                    <span class="input-group-btn">
                        <button class="btn btn-default" id="btnThumbnail" type="button">浏览…</button>
                    </span>
                </div><!-- /input-group -->
                @Html.ValidationMessageFor(model => model.Thumbnail)
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.Stalls, new { @class = "col-md-2 control-label" })
            <div class="col-md-10">
                @Html.TextBoxFor(model => model.Stalls, new { @class = "form-control", placeholder = Labels.Stalls })

                @Html.ValidationMessageFor(model => model.Stalls)
            </div>
        </div>
        <div class="form-group">
            @Html.LabelFor(model => model.Voltage, new { @class = "col-md-2 control-label" })
            <div class="col-md-10">
                @Html.TextBoxFor(model => model.Voltage, new { @class = "form-control", placeholder = Labels.Voltage })

                @Html.ValidationMessageFor(model => model.Voltage)
            </div>
        </div>
        <div class="form-group">
            @Html.LabelFor(model => model.TankCapacity, new { @class = "col-md-2 control-label" })
            <div class="col-md-10">
                @Html.TextBoxFor(model => model.TankCapacity, new { @class = "form-control", placeholder = Labels.TankCapacity })

                @Html.ValidationMessageFor(model => model.TankCapacity)
            </div>
        </div>
        <div class="form-group">
            @Html.LabelFor(model => model.WaterPressure, new { @class = "col-md-2 control-label" })
            <div class="col-md-10">
                @Html.TextBoxFor(model => model.WaterPressure, new { @class = "form-control", placeholder = Labels.WaterPressure })

                @Html.ValidationMessageFor(model => model.WaterPressure)
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.Importance, new { @class = "col-md-2 control-label" })
            <div class="col-md-10">
                @Html.TextBoxFor(model => model.Importance, new { @class = "form-control", type = "number", placeholder = ModelMetadata.FromLambdaExpression(x => x.Importance, ViewData).Watermark })

                @Html.ValidationMessageFor(model => model.Importance)
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.Body, new { @class = "col-md-2 control-label" })
            <div class="col-md-10">
                @Html.TextAreaFor(model => model.Body, new { placeholder = "内容" })
                @Html.ValidationMessageFor(model => model.Body)
            </div>
        </div>

        <div class="form-group">
            <div class="col-md-5 col-md-offset-2">
                <div class="checkbox">
                    <label>
                        @Html.CheckBoxFor(model => model.Recommend)  @Html.DisplayNameFor(model => model.Recommend)
                    </label>
                </div>
            </div>
            <div class="col-md-5">
                @Html.ValidationMessageFor(model => model.Recommend)
            </div>
        </div>

        <div class="form-group">
            <div class="col-md-5 col-md-offset-2">
                <div class="checkbox">
                    <label>
                        @Html.CheckBoxFor(model => model.Active)  @Html.DisplayNameFor(model => model.Active)
                    </label>
                </div>
            </div>
            <div class="col-md-5">
                @Html.ValidationMessageFor(model => model.Active)
            </div>
        </div>

        <div class="form-group">
            <div class="col-sm-offset-2 col-md-10">
                <button type="submit" class="btn btn-primary" id="btnSave"><i class="fa fa-save fa-fw"></i>  @Buttons.Update </button>
                <a href="@Url.Action("Index")" class="btn btn-default"><span class="glyphicon glyphicon-arrow-left"></span> @Buttons.Back</a>
            </div>
        </div>

}

    </section>
    <footer class="box-footer"></footer>

</div>


@Html.Action("PopuFinder", "File")
@section Footer {
    @Scripts.Render("~/bundles/jqueryvalWithBootstrap")
    <script src="/Plugins/webuploader/webuploader.min.js"></script>
    <script src="/Plugins/SigFinder/FileManager.js"></script>
    <script src="~/plugins/ueditor/ueditor.config.js"></script>
    <script src="~/plugins/ueditor/ueditor.all.min.js"></script>

    <script>
        var ue = UE.getEditor('Body');

        function SetThumbnail() {
            var fileUrl = $("#fileList .item.active").attr("data-file");
            $('#Thumbnail').val(fileUrl);
            $('#fileManagerModal').modal('hide');
        }

        function onBeginSave() {
            $("#btnSave i").removeClass("fa-save").addClass("fa-spinner fa-spin");
        }
        function onCompleteSave() {
            $("#btnSave i").removeClass("fa-spinner fa-spin").addClass("fa-save");
        }

    function updateSuccess(data) {
        var title = '@ViewBag.Title';
        Common.ShowBox(data.Status, data.Message, title);
    }



    $(function () {
        $("#btnThumbnail").on("click", function () {
            $('#fileManagerModal').modal();
            $("#selectImage").unbind('click');
            $("#selectImage").bind("click", function () {
                SetThumbnail();
            });
        });
    });

    </script>
}